import javax.swing.tree.TreeNode;

class Solution {
    static class TreeNode{
        public char val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(char val){
            this.val = val;
        }
    }
    //相同的树
        public boolean isSameTree(TreeNode p, TreeNode q){
            if (p == null && q != null || p != null && q == null){
                return false;
            }
            if (p == null && q == null){
                return true;
            }
            if (p.val != q.val){
                return false;
            }
            //p != null && q != null && p.val == q.val
            return isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }

        //另一棵树的子树
        public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if (root == null || subRoot == null){
            return false;
        }
        if (isSameTree(root, subRoot)){
            return true;
        }
        if (isSubtree(root.left, subRoot)){
            return true;
        }
        if (isSubtree(root.right,subRoot)){
            return true;
        }
        return false;

        }
}
